package com.fh.rabbit;

import com.fh.rabbit.MyAckReceiver;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitListenerConfig {

    @Autowired
    private CachingConnectionFactory connectionFactory;

    @Autowired
    private MyAckReceiver myAckReceiver;
    @Bean
    public SimpleMessageListenerContainer simpleMessageListenerContainer(){
        SimpleMessageListenerContainer container=new SimpleMessageListenerContainer(connectionFactory);
        // 设置多个并发消费者一起消费，并支持运行时动态修改
        container.setConcurrentConsumers(1);
        // 设置最多的并发消费者
        container.setMaxConcurrentConsumers(1);
        //设置手动确认
        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        //设置队列
        container.setQueueNames("orderQueue");
        container.setMessageListener(myAckReceiver);
        return container;


    }
}